package com.ctshk.rpc.localfun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.dto.Result;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.rpc.localfun.dto.LocalFunProductCostStrategySpecAttrDTO;
import com.ctshk.rpc.localfun.entity.LocalFunProductCostStrategySpecAttr;
import com.ctshk.rpc.localfun.entity.LocalFunProductTicket;
import com.ctshk.rpc.localfun.mapper.LocalFunProductCostStrategySpecAttrMapper;
import com.ctshk.rpc.localfun.mapper.LocalFunProductTicketMapper;
import com.ctshk.rpc.localfun.req.LocalFunProductTicketDetailReq;
import com.ctshk.rpc.localfun.service.ILocalFunProductCostStrategySpecAttrService;
import com.google.common.collect.Lists;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description
 * @Author wansi <gaylen15527491065@yeah.net>
 * @Date 2021/3/30
 */
@DubboService
public class LocalFunProductCostStrategySpecAttrServiceImpl extends ServiceImpl<LocalFunProductCostStrategySpecAttrMapper, LocalFunProductCostStrategySpecAttr> implements ILocalFunProductCostStrategySpecAttrService {

    @Autowired
    LocalFunProductCostStrategySpecAttrMapper scenicProductCostStrategySpecAttrMapper;

    @Autowired
    LocalFunProductTicketMapper scenicProductTicketMapper;


    @Override
    public Result<List<LocalFunProductCostStrategySpecAttrDTO>> specAttrName(LocalFunProductTicketDetailReq scenicProductTicketDetailReq) {
        String idStr = scenicProductTicketDetailReq.getId();
        String[] split = StringUtils.delimitedListToStringArray(idStr,",");
        List<Long> ids = Arrays.stream(split).filter(id->StringUtils.isNotEmpty(id) && !"null".equals(id)).map(id -> Long.valueOf(id)).collect(Collectors.toList());
        List<LocalFunProductCostStrategySpecAttr> costStrategySpecAttrs = scenicProductCostStrategySpecAttrMapper.selectBatchIds(Lists.newArrayList(ids));
        List<LocalFunProductCostStrategySpecAttrDTO> strategySpecAttrDTOS = EntityUtil.copyList(costStrategySpecAttrs, LocalFunProductCostStrategySpecAttrDTO.class);
        return Result.success(strategySpecAttrDTOS);
    }
}
